/*********************************************************************
* File: ICombat.h
*
* Implements the communication API.
*********************************************************************/
#pragma once

#include "../../engine.h"
#include "../interfaces/ICommunication.h"
using namespace agents::interfaces;

#include <queue>
using namespace std;

namespace agents{ class Agent; }

namespace agents{ namespace modules{
	/**
	* \brief Implements the communication API.
	* 
	* Supports predefined radio-based and generic chat-based communication.
	*
	* \author Instituto Superior Tecnico de Lisboa, Portugal
	* \author Technical University of Lisbon, Portugal
	* 
	* \author Agentes Autonomos e Sistemas Multiagente
	* \author Autonomous Agents and Multiagent Systems
	* 
	* \version	1.0
	* \date		2006/2007
	**/
	class Communication: public ICommunication{
	public:
		Communication(Agent &owner);
		~Communication();

		void newRound();

		void sayText(const char *pText);
		void teamSayText(const char *pText);
		bool receiveMsg(SayMessages::Enumeration sayMsgType, MessageRecord* record);
		void sendRadioMessage(RadioMessages::Enumeration msg);
		bool receiveRadioMsg(RadioMessageRecord* record);

		void pushSayMessage(const char* msg, edict_t *sender);		
		void pushSayTeamMessage(const char* msg, edict_t *sender);
		void pushSayDeadMessage(const char* msg, edict_t *sender);	
		void pushRadioMessage(RadioMessages::Enumeration msg, edict_t *sender);

	protected:
		/** 
		* \brief The agent. 
		**/
		Agent &_owner;

	private:
		MessageRecord* createMessageRecord(const char* msg, edict_t *sender);
		bool receiveMsg(queue<MessageRecord*>* inbox, MessageRecord* record);

		/** 
		* \brief Say messages inbox.
		**/
		queue<MessageRecord*>* _sayMsgInbox;
		/** 
		* \brief SayTeam messages inbox.
		**/
		queue<MessageRecord*>* _sayTeamMsgInbox;
		/** 
		* \brief ChatType::dead messages inbox.
		**/
		queue<MessageRecord*>* _sayDeadMsgInbox;
		/** 
		* \brief Radio messages inbox.
		**/
		queue<RadioMessageRecord*>* _radioMsgInbox;
	};
}}